<template>
    <h1>用户添加页面</h1>

    <table>
        <tr>
            <td>用户名</td>
            <td>
                <input type="text" v-model="Add.U_Name" />
            </td>
        </tr>

        <tr>
            <td>密码</td>
            <td>
                <input type="password" v-model="Add.U_Pwd" />
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="添加" @click="AddUser" />
            </td>
        </tr>

    </table>

</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const router = useRouter();

const Add = ref({
    U_Name:'',
    U_Pwd:''
})

const AddUser =()=>{
    axios({
        method:'post',
        url:'http://localhost:62821/api/User/AddUser',
        data:{
            U_Name:Add.value.U_Name,
            U_Pwd:Add.value.U_Pwd
        }
    })
    .then(res=>{
        if(res.data>0){
            alert('添加成功');
            router.push('/UserShow');
        }
        else{
            alert('添加失败');
        }
        console.log(res.data);
    })
    .catch(err=>{
        console.log(err);
    })
}

</script>
